/**
 * Copyright (C) 2007 The AsyncMail Group <asyncmail@googlegroups.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.asyncmail.smtpserver;

import com.googlecode.asyncmail.smtp.SMTPResponse;
import com.googlecode.asyncmail.smtpserver.handler.LineHandler;

import java.util.Map;

/**
 * All the handlers access this interface to communicate with SMTPHandler object
 */

public interface SMTPSession {

    // Keys used to store/lookup data in the internal state hash map
    public final static String CURRENT_HELO_MODE = "CURRENT_HELO_MODE"; // HELO
                                                                        // or

    // EHLO

    public final static String CURRENT_HELO_NAME = "CURRENT_HELO_NAME";

    public final static String SESSION_STATE_MAP = "SESSION_STATE_MAP"; // the

    // Session
    // state

    public final static String MAIL_ENVELOPE = "MAIL_ENVELOPE";

    /**
     * Returns host name of the client
     * 
     * @return hostname of the client
     */
    String getRemoteHost();

    /**
     * Returns host ip address of the client
     * 
     * @return host ip address of the client
     */
    String getRemoteIPAddress();

    /**
     * Returns Map that consists of the state of the SMTPSession per mail
     * 
     * @return map of the current SMTPSession state per mail
     */
    Map<String, Object> getState();

    /**
     * Resets message-specific, but not authenticated user, state.
     * 
     */
    void resetState();

    /**
     * Returns SMTPHandler service wide configuration
     * 
     * @return SMTPHandlerConfigurationData
     */
    SMTPHandlerConfigurationData getConfigurationData();

    /**
     * Returns whether Relaying is allowed or not
     * 
     * @return the relaying status
     */
    boolean isRelayingAllowed();

    /**
     * Returns the user name associated with this SMTP interaction.
     * 
     * @return the user name
     */
    String getUser();

    /**
     * Sets the user name associated with this SMTP interaction.
     * 
     * @param user
     *                the user name
     */
    void setUser(String user);

    /**
     * Returns the SMTP session id
     * 
     * @return SMTP session id
     */
    String getSessionID();

    /**
     * Returns Map that consists of the state of the SMTPSession per connection
     * 
     * @return map of the current SMTPSession state per connection
     */
    Map<String, Object> getConnectionState();

    /**
     * Put a new line handler in the chain
     * 
     * @param overrideCommandHandler
     */
    void pushLineHandler(LineHandler overrideCommandHandler);

    /**
     * Pop the last command handler
     */
    void popLineHandler();

    /**
     * Used to write an SMTPResponse
     * 
     * @param response
     */
    void writeSMTPResponse(SMTPResponse response);
}